package com.ruoyi.web.controller.sms;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SmsPrize;
import com.ruoyi.system.service.ISmsPrizeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 奖品Controller
 *
 * @author DRIES
 * @date 2022-03-09
 */
@RestController
@RequestMapping("/sms/prize")
public class SmsPrizeController extends BaseController
{
    @Autowired
    private ISmsPrizeService smsPrizeService;

    /**
     * 查询奖品列表
     */
    @PreAuthorize("@ss.hasPermi('sms:prize:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsPrize smsPrize)
    {
        startPage();
        List<SmsPrize> list = smsPrizeService.selectSmsPrizeList(smsPrize);
        return getDataTable(list);
    }

    /**
     * 导出奖品列表
     */
    @PreAuthorize("@ss.hasPermi('sms:prize:export')")
    @Log(title = "奖品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmsPrize smsPrize)
    {
        List<SmsPrize> list = smsPrizeService.selectSmsPrizeList(smsPrize);
        ExcelUtil<SmsPrize> util = new ExcelUtil<SmsPrize>(SmsPrize.class);
        util.exportExcel(response, list, "奖品数据");
    }

    /**
     * 获取奖品详细信息
     */
    @PreAuthorize("@ss.hasPermi('sms:prize:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(smsPrizeService.selectSmsPrizeById(id));
    }

    /**
     * 新增奖品
     */
    @PreAuthorize("@ss.hasPermi('sms:prize:add')")
    @Log(title = "奖品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmsPrize smsPrize)
    {
        return toAjax(smsPrizeService.insertSmsPrize(smsPrize));
    }

    /**
     * 修改奖品
     */
    @PreAuthorize("@ss.hasPermi('sms:prize:edit')")
    @Log(title = "奖品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmsPrize smsPrize)
    {
        return toAjax(smsPrizeService.updateSmsPrize(smsPrize));
    }

    /**
     * 删除奖品
     */
    @PreAuthorize("@ss.hasPermi('sms:prize:remove')")
    @Log(title = "奖品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsPrizeService.deleteSmsPrizeByIds(ids));
    }
}
